Skip to content

Conversation

@ChrisPulman
Copy link
Member

What kind of change does this PR introduce?

feature

What is the current behavior?

IViewFor can register a View in Splat

What is the new behavior?

Introduces ViewModelRegistrationType to the IViewFor attribute and updates generator logic to support separate Splat registration for view models. Documentation, tests, and source generator code are updated to reflect the new option and ensure correct registration behavior.

What might this PR break?

None, new feature

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

Introduces ViewModelRegistrationType to the IViewFor attribute and updates generator logic to support separate Splat registration for view models. Documentation, tests, and source generator code are updated to reflect the new option and ensure correct registration behavior.
@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

❌ Patch coverage is 38.46154% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.98%. Comparing base (ecb5527) to head (2d43968).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ators.Roslyn/IViewFor/IViewForGenerator.Execute.cs 6.89% 23 Missing and 4 partials ⚠️
...UI.SourceGenerators.Roslyn/AttributeDefinitions.cs 85.71% 3 Missing ⚠️
...eGenerators.Roslyn/IViewFor/Models/IViewForInfo.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #341      +/-   ##
==========================================
- Coverage   40.04%   39.98%   -0.06%     
==========================================
  Files          61       61              
  Lines        3389     3429      +40     
  Branches      389      395       +6     
==========================================
+ Hits         1357     1371      +14     
- Misses       1926     1948      +22     
- Partials      106      110       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Added [ExcludeFromCodeCoverage] attribute to various test and sample classes across the project to exclude them from code coverage analysis. This helps ensure that code coverage metrics focus on production code rather than test scaffolding.
Deleted the [ExcludeFromCodeCoverage] attribute from several test-related classes to allow code coverage tools to include these files. This change may help improve visibility into test code coverage metrics.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the ViewModelRegistrationType property to the IViewForAttribute, enabling separate Splat registration for ViewModels alongside the existing View registration. This allows developers to automatically register ViewModels in the dependency injection container when configuring their Views.

Key Changes

  • Added ViewModelRegistrationType property to both generic and non-generic IViewForAttribute variants
  • Extended IViewForInfo model to include SplatViewModelRegistrationType field
  • Updated source generator logic to process and generate separate ViewModel registrations
  • Updated documentation and test examples to demonstrate the new feature

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/Models/IViewForInfo.cs Added SplatViewModelRegistrationType parameter to the model record and removed unused import
src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/IViewForGenerator.Execute.cs Added logic to extract and process ViewModelRegistrationType from attributes and generate corresponding ViewModel registrations
src/ReactiveUI.SourceGenerators.Roslyn/AttributeDefinitions.cs Added ViewModelRegistrationType property to both IViewForAttribute variants with documentation; replaced hardcoded version strings with placeholder variables
src/ReactiveUI.SourceGenerators.Execute/TestViewWpf.cs Updated example usage to demonstrate both RegistrationType and ViewModelRegistrationType properties
src/ReactiveUI.SourceGenerators.Execute/TestViewWpf2.cs Added using System.Diagnostics.CodeAnalysis import
src/ReactiveUI.SourceGenerators.Execute/TestViewModel{partTwo}.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/TestViewModel3.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/TestViewModel2.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/TestClassOAPH_VM.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/TestAttribute.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/Program.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/Person.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute.Nested3/Class1.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute.Nested2/Class1.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute.Nested1/Class1.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs Added [ExcludeFromCodeCoverage] attribute
src/ReactiveUI.SourceGenerators.Execute.Maui/IViewForTest.cs Added import for System.Diagnostics.CodeAnalysis
src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs Replaced obsolete VersionRange.AllStableFloating with VersionRange.AllStable
src/ReactiveUI.SourceGenerator.Tests/IVIEWFOR/IViewForGeneratorTests.FromIViewFor#ReactiveUI.SourceGenerators.IViewForAttribute.g.verified.cs Updated verified test output to include new ViewModelRegistrationType property
src/ReactiveUI.SourceGenerators.Execute/TestWinFormsVMCHost.cs Added import for System.Diagnostics.CodeAnalysis
src/ReactiveUI.SourceGenerators.Execute/TestWinFormsRCHost.cs Added import for System.Diagnostics.CodeAnalysis
README.md Updated documentation to mention both IViewFor and ViewModel registration options and updated example usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changed the grouping key from SplatRegistrationType to SplatViewModelRegistrationType in viewModelRegistrations to ensure correct grouping of ViewModel registration types.
Updated XML comments to specify that the ViewModel (T) is registered in the Splat service locator, instead of IViewFor<T>. This improves clarity for consumers of the attribute.
Clarifies XML documentation to specify that ViewModel (T) is registered in the Splat service locator, instead of IViewFor<T>. Adds new received test file for .NET 10.0 verifying the generated attribute code.
Added checks to skip processing registrations where ViewModelTypeName is null, empty, or whitespace. This prevents potential errors from invalid or incomplete registration data.
@ChrisPulman ChrisPulman enabled auto-merge (squash) December 8, 2025 02:13
@ChrisPulman ChrisPulman disabled auto-merge December 8, 2025 02:14
Simplifies vmType handling by removing redundant string.IsNullOrEmpty checks before prefixing with 'global::'. This change assumes vmType is always non-null and non-empty at this point in the code.
@ChrisPulman ChrisPulman merged commit f283e27 into main Dec 8, 2025
4 of 6 checks passed
@ChrisPulman ChrisPulman deleted the AddViewModelRegistrationToIViewFor branch December 8, 2025 02:23
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants